
package com.dailytechlab.repository;

import com.dailytechlab.model.PracticeRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface PracticeRecordRepository extends JpaRepository<PracticeRecord, Long> {
    
    @Query("SELECT COUNT(p) FROM PracticeRecord p WHERE p.userId = ?1 AND DATE(p.createdAt) = CURRENT_DATE")
    long countTodayPractices(String userId);
    
    @Query("SELECT COUNT(DISTINCT p.module.id) FROM PracticeRecord p WHERE p.userId = ?1 AND p.isCompleted = true")
    long countCompletedModules(String userId);
    
    @Query("SELECT COALESCE(SUM(p.linesOfCode), 0) FROM PracticeRecord p WHERE p.userId = ?1")
    long sumTotalLinesOfCode(String userId);
    
    List<PracticeRecord> findByUserIdOrderByCreatedAtDesc(String userId);
}
